from fastapi import FastAPI
from pydantic import BaseModel
import json,re,os,sys
from ApiTools import apiTools,apiBase
from ApiModels import apiModels

from starlette.responses import JSONResponse
from dotenv import load_dotenv

class LlmParam(BaseModel):
    name: str
    param0: str
    param1: str
    param2: str
    param3: str
    param4: str
    param5: str

apiBase.dir_func("./")
apiTools.load_vec()
apiTools.load_grp()
apiTools.load_tol()
apiTools.load_rft()
apiTools.load_sft()
apiTools.load_act()

# ret=apiBase.funs_run['info'](['aaa'])
# print(ret)
app = FastAPI()
@app.post("/llm")
def llm_run(llmParam:LlmParam):
    # 按空格分解
    params=[]
    # 可以实现不同函数之间的调用
    params.append(apiBase.funs_run)
    params.append(llmParam.param0)
    params.append(llmParam.param1)
    params.append(llmParam.param2)
    params.append(llmParam.param3)
    params.append(llmParam.param4)
    params.append(llmParam.param5)
    
    #print(params)
    try:
        if apiBase.funs_run[llmParam.name]:
            ret=apiBase.funs_run[llmParam.name](params)
            return JSONResponse(content=ret, status_code=200)
    except Exception as e:
        JSONResponse(content=str(e), status_code=200)
    return  JSONResponse(content='" No functon run"', status_code=200)

if __name__ == '__main__':
    import uvicorn
    uvicorn.run(app,host="127.0.0.1",port=61818)